package com.g4.shoppingback.service.impl;

import com.g4.shoppingback.common.PageVo;
import com.g4.shoppingback.common.Result;
import com.g4.shoppingback.mapper.AddressMapper;
import com.g4.shoppingback.mapper.DdOrderInfoMapper;
import com.g4.shoppingback.mapper.DdUsersInfoMapper;
import com.g4.shoppingback.pojo.DdOrderInfo;
import com.g4.shoppingback.pojo.DdUsersInfo;
import com.g4.shoppingback.service.DdOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DdOrderInfoServiceImpl implements DdOrderInfoService {

    @Autowired
    private DdOrderInfoMapper ddOrderInfoMapper;

    /**
     * 根据分页信息或订单名查询订单
     * @param pageVo 封装了页数和关键字
     * @return 返回分页信息
     */
    @Override
    public Result selectOrderByPage(PageVo pageVo) {
        Integer pageSize = 5;   //设置每页固定显示5条数据
        Integer pageStart = (pageVo.getPageNum()-1)*pageSize;   //设置从第几条开始
        Long total = ddOrderInfoMapper.selectTotal(pageVo.getQuery());  //查询总条数
        List<DdOrderInfo> orderInfos = ddOrderInfoMapper.selectOrderByPage(pageVo.getQuery(),pageStart,pageSize);
        pageVo.setPageSize(pageSize).setTotal(total).setRows(orderInfos); //封装分页信息
        return Result.ok(pageVo);
    }

    /**
     * 根据id修改发货状态
     * @param ddOrderInfo 订单id和状态
     * @return 影响行数
     */
    @Override
    public int updateDelivery(DdOrderInfo ddOrderInfo) {
        int row = ddOrderInfoMapper.updateById(ddOrderInfo);
        return row;
    }

    /**
     * 根据id修改地址
     * @param ddOrderInfo 订单id和地址id
     * @return 影响行数
     */
    @Override
    public int updateAddressId(DdOrderInfo ddOrderInfo) {
        int row = ddOrderInfoMapper.updateById(ddOrderInfo);
        return row;
    }
}
